<?php
/**
 * @title 2215. 找出两数组的不同
 * @author start2004
 */

// ini_set("memory_limit", "128M");

// class Solution {
//
//     function find() {
//
//     }
// }

class Solution {

    /**
     * @param Integer[] $nums1
     * @param Integer[] $nums2
     * @return Integer[][]
     */
    function findDifference($nums1, $nums2) {
        /**
         * @since 2024-01-09 变成hash
         */
        $hash1 = $this->HashArray($nums1);
        $hash2 = $this->HashArray($nums2);

        /**
         * @since 2024-01-09 返回不同的值
         * @return [Integer[], Integer[]]
         */
        return [$this->DiffArray($hash1, $hash2), $this->DiffArray($hash2, $hash1)];
    }

    /**
     * @title 数组转成hash
     * @author start2004
     * @since 2024-01-09 Created
     *
     * @param Integer[] $nums
     * @return Integer[]
     */
    function HashArray($nums){
        /**
         * @since 2024-01-09 哈希数组
         */
        $hashArray = [];

        /**
         * @since 2024-01-09 遍历数组
         */
        foreach ($nums as $num){
            $hashArray[$num] = $num;
        }

        /**
         * @return Integer[]
         */
        return $hashArray;
    }

    /**
     * @title 返回存在hash1，不存在于hash2的元素集合
     * @author start2004
     * @since 2024-01-09 Created
     *
     * @param Integer[] $hash1
     * @param Integer[] $hash2
     * @return Integer[]
     */
    function DiffArray($hash1, $hash2){
        /**
         * @since 2024-01-09 不同的值
         */
        $diffArray = [];

        /**
         * @since 2024-01-09 遍历数组
         */
        foreach ($hash1 as $num){
            /**
             * @since 2024-01-09 hash2不存在该值
             */
            if(!isset($hash2[$num])){
                $diffArray[] = $num;
            } else {}
        }

        /**
         * @return Integer[]
         */
        return $diffArray;
    }
}


/**
 * @url http://127.0.0.1/leetcode/202401/2024.01.09_6.php
 */
$datas = [

];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    if(count($data) <= 20){
        var_dump($data);
    } else {
        var_dump(count($data));
    }

    $obj = new Solution();
    $result = $obj->(...$data);
    // $result = $obj->($xhprof->tree($data));
    // $result = $obj->($xhprof->listNode($data));
    // $result = $obj->find(...$data);
    var_dump($result);
    // if(count($result)<=20){
    //     var_dump($result);
    // } else {
    //     var_dump(count($result));
    // }
    echo str_repeat(PHP_EOL, 3);
    echo str_repeat("<br>", 3);
}

// foreach ($datas as $data){
//     $obj = new $data[0][0](...$data[1][0]);
//
//     for ($i=1; $i<count($data[0]); $i++){
//         $func = $data[0][$i];
//         $param = $data[1][$i];
//         $result = $obj->$func(...$param);
//
//         echo $data[0][$i] ."(\"". implode(",", $data[1][$i]) ."\") ";
//             if($result === true){
//                 echo "True";
//             } elseif($result === false) {
//                 echo "False";
//             } elseif($result === null) {
//                 echo "Null";
//             } elseif(is_array($result)) {
//                 var_dump($result);
//             } else {
//                 echo $result;
//             }
//         echo PHP_EOL;
//     }
//
//     echo str_repeat(PHP_EOL, 3);
// }
$xhprof->end();
